var t = require('../../../../@babel/runtime/helpers/defineProperty'),
  e = require('../../../../@babel/runtime/helpers/regeneratorRuntime'),
  n = require('../../../../@babel/runtime/helpers/asyncToGenerator'),
  o = getApp(),
  i = null,
  r = null;
Component({
  behaviors: [],
  properties: {
    goodsData: { value: {}, type: Object },
    discountList: { value: [], type: Array },
    is_collect: { value: 0, type: Number },
    is_no_reason: { value: 0, type: Number },
    return_remark: { value: '', type: String },
    drawActiveData: { value: {}, type: Object },
    is_credit: { value: '0', type: String },
    pin_activity_info: {
      value: {},
      type: Object,
      observer: function (t) {
        this.setData({ _pin_activity_info: t }),
          t && t.list && t.list.length && this.countDown_pt();
      },
    },
    buyData: { type: Object, value: {} },
    goodsType: {
      value: {},
      type: Object,
      observer: function (t) {
        this.setData({ _goodsType: t }),
          t && t.showGroupInfo && this.countDown(t.timeCount);
      },
    },
    upObj: { value: {}, type: Object },
  },
  observers: {
    'is_credit, discountList, drawActiveData, buyData, goodsType, is_no_reason':
      function (t, e, n, o, a, i) {
        var r = {},
          s = 0;
        '0' != t && s++;
        var c = 0;
        s <= 0 &&
          o.hasOwnProperty('today_rank_num') &&
          o.today_rank_num &&
          ((c = o.today_rank_num || 0),
          (r.today_rank_num = o.today_rank_num || 0),
          this.setData(r));
        var u = '';
        'weidou' != a.type &&
          (e.length > 0 && s++,
          n.is_draw && s++,
          (u =
            e.length && 'weidou' != a.type
              ? 'coupon'
              : 0 == c || e.length
                ? i
                  ? 'no_reason'
                  : ''
                : 'rank'),
          (r.block_name = u),
          u && s++),
          this.setData(r);
      },
  },
  data: {
    showTime: '',
    upName: '',
    upImg: '',
    _goodsType: {},
    CONFIG: o.CONFIG,
    today_rank_num: 0,
    _pin_activity_info: {},
    render_sq_flag: !1,
    sq_pop_data: {},
    block_name: '',
  },
  lifetimes: {
    attached: function () {
      var t = wx.getStorageSync('initSystem');
      this._getQRcode(),
        this.setData({ show_list_price: t.show_list_price || 0 });
    },
    detached: function () {
      clearTimeout(i);
    },
  },
  methods: {
    _showrr: function () {
      this.triggerEvent('showrr');
    },
    _getQRcode: function () {
      var t = this;
      return n(
        e().mark(function n() {
          var a;
          return e().wrap(function (e) {
            for (;;)
              switch ((e.prev = e.next)) {
                case 0:
                  return (
                    (e.next = 2),
                    o.$api.user.getQrcode({
                      position: 'home',
                      uid: wx.getStorageSync('rid') || 0,
                    })
                  );
                case 2:
                  (a = e.sent).hasOwnProperty('community_qrcode') &&
                  a.community_qrcode.hasOwnProperty('qrcode_url') &&
                  a.community_qrcode.qrcode_url
                    ? t.setData({ render_sq_flag: !0, sq_pop_data: a })
                    : t.setData({ render_sq_flag: !1 });
                case 4:
                case 'end':
                  return e.stop();
              }
          }, n);
        }),
      )();
    },
    _openSheQun: function () {
      this.setData({ show_sq_flag: !0 }),
        this.selectComponent('#SQ_POP')._show();
    },
    _closeSQPop: function () {
      this.setData({ show_sq_flag: !1 });
    },
    toggleCouponWrap: function () {
      this.setData({ showCouponWrap: !this.data.showCouponWrap });
    },
    goShare: function (t) {
      this.triggerEvent('goShare', t);
    },
    goHome: function () {
      this.data.render_sq_flag;
      wx.switchTab({ url: '/pages/index/index' });
    },
    _hackB: function () {},
    _copy: function (t) {
      var e = t.currentTarget.dataset.text;
      wx.setClipboardData({
        data: e,
        success: function (t) {
          wx.showToast({
            title: '已复制到粘贴板',
            icon: 'none',
            duration: 1200,
          });
        },
      });
    },
    returnTime: function (t) {
      var e = Math.floor(t / 86400) < 0 ? 0 : Math.floor(t / 86400),
        n = 0 === e ? t : t % 86400,
        o = Math.floor(n / 3600) < 0 ? 0 : Math.floor(n / 3600),
        a = n % 3600,
        i = Math.floor(a / 60) < 0 ? 0 : Math.floor(a / 60),
        r = a % 60,
        s = r % 60 < 0 ? 0 : r % 60,
        c = ''
          .concat(e, '天')
          .concat(o >= 10 ? o : '0' + o, ':')
          .concat(i >= 10 ? i : '0' + i, ':')
          .concat(s >= 10 ? s : '0' + s),
        u = Math.floor(t / 3600) < 0 ? 0 : Math.floor(t / 3600);
      return {
        timeStr_text: c,
        timeStr_num: ''
          .concat(u >= 10 ? u : '0' + u, ':')
          .concat(i >= 10 ? i : '0' + i, ':')
          .concat(s >= 10 ? s : '0' + s),
        time_obj: {
          day: e,
          hours: o >= 10 ? o : '0' + o,
          min: i >= 10 ? i : '0' + i,
          s: s >= 10 ? s : '0' + s,
        },
      };
    },
    countDown_pt: function () {
      var e = this;
      clearTimeout(r);
      var n = this.data._pin_activity_info.list,
        o = 999999999;
      r = setTimeout(function () {
        n.map(function (n, a) {
          var i,
            r = e.returnTime(n.seconds_remaining--).timeStr_num;
          e.setData(
            (t(
              (i = {}),
              '_pin_activity_info.list['.concat(a, '].time_format'),
              r,
            ),
            t(
              i,
              '_pin_activity_info.list['.concat(a, '].seconds_remaining'),
              n.seconds_remaining--,
            ),
            i),
          ),
            (o = n.seconds_remaining < o ? n.seconds_remaining : o);
        }),
          o > 0
            ? e.countDown_pt()
            : (clearTimeout(r), e.triggerEvent('pt_timeOut'));
      }, 1e3);
    },
    _collect: function () {
      this.triggerEvent('collect');
    },
    countDown: function (t) {
      var e = this;
      clearTimeout(i),
        (i = setTimeout(function () {
          var n = t - 1,
            o = e.returnTime(n),
            a = o.timeStr_text,
            r = o.timeStr_num,
            s = o.time_obj;
          e.triggerEvent('upWillDate', r),
            e.setData({ showTime: a, time_obj: s }),
            n > 0 ? e.countDown(n) : (e.outTime(), clearTimeout(i));
        }, 1e3));
    },
    outTime: function () {
      this.triggerEvent('timeOut');
    },
  },
});
